﻿REM this is a plugin sample with vbs

Sub Plugin_rule_withtag_p()
	dim sTag,i
	sTag="h1,h2,h3,h4,h5,h6,p"
	sTag=Split(sTag,",")
	For i=0 to Ubound(sTag)
		ruleTag(sTag(i))
	Next
End Sub

Sub ruleTag(sTagName)
	'on error resume next
	dim sTextAlign,sTextIndent,it,innerText
	For each it in EditContent.document.getElementsByTagName(sTagName)

		sTextAlign=it.style.textAlign
		sTextIndent=it.style.textIndent

		it.removeAttribute "className"
		it.removeAttribute "style"
		
		innerText=it.innerText
		if left(innerText,4)="    " then	'四个空格
			it.style.textIndent="2em"	'固定缩进2个字符
			innerText=mid(innerText,5)
		end if
		innerText=Replace(innerText," ","&nbsp;")
		it.innerHTML=innerText
		
		if sTextAlign<>"" then
			it.style.textalign=sTextAlign
		end if
		if sTextIndent<>"" then
			it.style.textIndent=sTextIndent
		end if
		if getNumeric(it.style.textIndent)<0 then
			it.style.textIndent=0
		end if
		if getNumeric(it.style.marginLeft)<0 then
			it.style.marginLeft=0
		end if
	Next
End Sub


Function getNumeric(sStr)
	if sStr="" then
		getNumeric=0
		exit function
	end if
	sStr=Lcase(sStr)
	sStr=Replace(sStr,"pt","")
	sStr=Replace(sStr,"px","")
	getNumeric=Replace(sStr,"em","")
End Function
